package com.jtjrenren.android.taxi.passenger.core.pay.main;

import com.baidu.mapapi.model.LatLng;
import com.jtjrenren.android.taxi.passenger.Constants;
import com.jtjrenren.android.taxi.passenger.manger.AppManger;
import com.jtjrenren.android.taxi.passenger.manger.api.ApiWorks;
import com.jtjrenren.android.taxi.passenger.utils.ModuleUtils;

import com.library.utils.LogUtil;
import com.library.utils.StringUtils;

/**
 * Created by wdl on 2016/9/21.
 */

public class PayInteractorImpl implements PayInteractor {

    @Override
    public void getOrderDetails(String orderID, ApiWorks.ResponseListener listener) {
        ApiWorks.getOrderDetailByOrderSerNo(orderID, listener);
    }

    @Override
    public void getBestCoupons(String userID, String price, int orderType, ApiWorks.ResponseListener listener) {
        LatLng loc = null;
        if (AppManger.getInstance().currentLocation != null)
            loc = new LatLng(AppManger.getInstance().currentLocation.getLatitude(),
                    AppManger.getInstance().currentLocation.getLongitude());
        String lat = loc == null ? Constants.DEFAULT_LAT : loc.latitude + "";
        String lng = loc == null ? Constants.DEFAULT_LNG : loc.longitude + "";

        ApiWorks.getCouponBest(userID, lat, lng, StringUtils.isEmpty(price) ? "0" : price, orderType + "",
                listener);
    }


    @Override
    public void payN(String orderID, String money, String payMode, String couponsID, String couponsAmt,
                     ApiWorks.ResponseListener listener) {
        pay("2", payMode, money, orderID, couponsID, couponsAmt, listener);
    }


    public void pay(String type, String payMode, String money, String orderID,
                    String CouponsID, String CouponsAmt,
                    final ApiWorks.ResponseListener<String> listener) {
        if (StringUtils.isEmpty(orderID))
            orderID = "";
        if (StringUtils.isEmpty(CouponsID))
            CouponsID = "";
        if (StringUtils.isEmpty(CouponsAmt))
            CouponsAmt = "0";

        String userId = AppManger.getInstance().user.getWorkNo();

        LogUtil.log("pay", "发起支付的属性：" + userId+","+type+","+payMode+","+money+","+orderID+","+CouponsID+","+CouponsAmt);


        money = ModuleUtils.DesEncry(money);

        LogUtil.log("pay", "发起支付的属性2：" + userId+","+type+","+payMode+","+money+","+orderID+","+CouponsID+","+CouponsAmt);


        ApiWorks.payN(userId, type, payMode, money, orderID, CouponsID, CouponsAmt, listener);
    }
}
